package com.entor.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.entor.dao.FilesDaoI;
import com.entor.dao.NoticeDaoI;
import com.entor.model.Files;
import com.entor.model.Msg;
import com.entor.model.Notice;

@Service
public class NoticeService implements BaseServiceI<Notice>{

	@Autowired
	private NoticeDaoI ndi;
	@Autowired
	private FilesDaoI fdi;
	
	public List<Notice> find(Notice t) {
		List<Notice> list = ndi.find(t);
		List<Notice> ns = new ArrayList<Notice>();
		for (Notice n : list) {
			Files f = new Files();
			f.setTname("t_coc_notices");
			f.setTid(n.getId());
			List<Files> fs = fdi.find(f);
			n.setFs(fs);		
			ns.add(n);
		}
		
		return ns;
	}

	public Notice get(Notice t) {
		List<Notice> list = this.find(t);
		return list.size()>0?list.get(0):new Notice();
	}

	public Msg insert(Notice t) {
		Msg m = new Msg("保存失败", false);
		int i = ndi.insert(t);
		int size = this.find(new Notice()).size();
		if(i>0) m = new Msg("保存成功",true,size);
		return m;
	}

	public Msg batchInsert(String objs) {
		return null;
	}

	public Msg edit(Notice t) {
		// TODO Auto-generated method stub
		return null;
	}

	public Msg remove(Integer id) {
		// TODO Auto-generated method stub
		return null;
	}

	public Msg batchRemove(String ids) {
		// TODO Auto-generated method stub
		return null;
	}

}
